﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyThuoc.DAL
{
   public class TonKhoDAL:KetNoiDAL
    {
       public DataTable SelectAll_TonKho()
       {
           SqlCommand cmd = new SqlCommand("SelectAll_TonKho", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public DataTable SelectID_TonKho(int IDTonKho)
       {
           SqlCommand cmd = new SqlCommand("SelectAll_TonKho", Connect());
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.AddWithValue("@IDTon", IDTonKho);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt;
       }
       public int InsertTonKho(string IDPN, DateTime NgayNhap, DateTime NgaySX, DateTime HanSD, int SL_N, string IDToa, string IDThuoc, DateTime NgayXuat, int SL_X)
       {
          
               SqlCommand cmd = new SqlCommand("Insert_TonKho", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               //cmd.Parameters.AddWithValue("@IDTon", IDTon);
               cmd.Parameters.AddWithValue("@IDPN", IDPN);
               cmd.Parameters.AddWithValue("@NgayNhap", NgayNhap);
               cmd.Parameters.AddWithValue("@NgaySX", NgaySX);
               cmd.Parameters.AddWithValue("@HanSD", HanSD);
               cmd.Parameters.AddWithValue("@SL_N", SL_N);
               cmd.Parameters.AddWithValue("@IDToa", IDToa);
               cmd.Parameters.AddWithValue("@IDThuoc", IDThuoc);
               cmd.Parameters.AddWithValue("@NgayXuat", NgayXuat);
               cmd.Parameters.AddWithValue("@SL_X", SL_X);
             return  cmd.ExecuteNonQuery();
         
       }
       public int UpdateTonKho(int IDTon,string IDPN, DateTime NgayNhap, DateTime NgaySX, DateTime HanSD, int SL_N, string IDToa, string IDThuoc, DateTime NgayXuat, int SL_X)
       {
          
               SqlCommand cmd = new SqlCommand("Update_TonKho",Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDTon", IDTon);
               cmd.Parameters.AddWithValue("@IDPN", IDPN);
               cmd.Parameters.AddWithValue("@NgayNhap", NgayNhap);
               cmd.Parameters.AddWithValue("@NgaySX", NgaySX);
               cmd.Parameters.AddWithValue("@HanSD", HanSD);
               cmd.Parameters.AddWithValue("@SL_N", SL_N);
               cmd.Parameters.AddWithValue("@IDToa", IDToa);
               cmd.Parameters.AddWithValue("@IDThuoc", IDThuoc);
               cmd.Parameters.AddWithValue("@NgayXuat", NgayXuat);
               cmd.Parameters.AddWithValue("@SL_X", SL_X);
             return  cmd.ExecuteNonQuery();
           
       }
       public int Delete_TonKho(int IDTonKho)
       {
          
               SqlCommand cmd = new SqlCommand("SelectAll_TonKho", Connect());
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@IDTon", IDTonKho);
            return   cmd.ExecuteNonQuery();
          
       }
    }
}
